package cn.bestick.cblog.service.impl;

import java.util.List;

import cn.bestick.cblog.dao.ArticleDao;
import cn.bestick.cblog.dao.impl.ArticleDaoImpl;
import cn.bestick.cblog.dmo.Article;
import cn.bestick.cblog.dto.AboutDto;
import cn.bestick.cblog.dto.ArticleDto;
import cn.bestick.cblog.dto.ArticleLiteDto;
import cn.bestick.cblog.service.ArticleService;
import cn.bestick.cblog.util.PageBean;

public class ArticleServiceImpl implements ArticleService {
	private ArticleDao dao = null;

	public ArticleServiceImpl() {
		this.dao = new ArticleDaoImpl();
	}

	@Override
	public List<ArticleDto> searchArticles(Article article) {
		List<ArticleDto> results = null;
		try {
			results = this.dao.search(article);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return results;
	}

	@Override
	public List<ArticleDto> getArticles(PageBean pageBean) {
		List<ArticleDto> results = null;
		try {
			results = this.dao.pagenation(pageBean);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return results;
	}

	@Override
	public List<ArticleLiteDto> getRecentArticles() {
		List<ArticleLiteDto> results = null;
		try {
			results = this.dao.getRecentArticles();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return results;
	}

	@Override
	public ArticleDto getArticle(Integer id) {
		ArticleDto result = null;
		try {
			result = this.dao.get(id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public ArticleLiteDto getPreArticle(Integer id) {
		ArticleLiteDto result = null;
		try {
			result = this.dao.getPre(id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public ArticleLiteDto getNextArticle(Integer id) {
		ArticleLiteDto result = null;
		try {
			result = this.dao.getNext(id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public List<ArticleLiteDto> getArticlesByCategory(int categoryId) {
		List<ArticleLiteDto> results = null;
		try {
			results = this.dao.getByCategory(categoryId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return results;
	}

	@Override
	public List<ArticleLiteDto> getArchive() {
		List<ArticleLiteDto> results = null;
		try {
			results = this.dao.archive();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return results;
	}

	@Override
	public AboutDto getAbout() {
		AboutDto result = null;
		try {
			result = this.dao.getAbout();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public void updateAbout(AboutDto about) {
		try {
			this.dao.updateAbout(about);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public void saveAbout(AboutDto about) {
		try {
			this.dao.saveAbout(about);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public void updateArticle(Article article) {
		try {
			this.dao.update(article);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public void saveArticle(Article article) {
		try {
			this.dao.save(article);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public void deleteArticle(Integer id) {
		try {
			this.dao.delete(id);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public int count() {
		int result = 0;
		try {
			result = this.dao.count();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}
}
